﻿using System;
using System.Linq;
using DAL;
using Entity;
using Utils;

namespace BLL
{
    public class CtrLog
    {
        /// <summary>
        /// Thêm mới Log
        /// </summary>
        /// <param name="action"></param>
        /// <param name="info"> </param>
        /// <param name="function"></param>
        /// <returns></returns>
        public static int InsertLog(char action, string info, string function)
        {
            return DB.AdminInstance.uspLogInsert(AdminUtils.AdminID, AdminUtils.UserName, action, info, function, AdminUtils.ServicesID, DateTime.Now);
        }

        /// <summary>
        /// Tìm kiếm danh sách nhật ký sử dụng
        /// </summary>
        /// <param name="keyWord"></param>
        /// <param name="adminID"></param>
        /// <param name="functionID"></param>
        /// <param name="action"></param>
        /// <param name="servicesID"> </param>
        /// <param name="fromDate"></param>
        /// <param name="toDate"></param>
        /// <param name="currentPage"></param>
        /// <param name="pageSize"></param>
        /// <returns></returns>
        public ClassExtend<int, uspLogGetListResult> GetListLog(string keyWord, int adminID, int functionID, char action, int servicesID, DateTime fromDate, DateTime toDate, int currentPage, int pageSize)
        {
            var objReturn = new ClassExtend<int, uspLogGetListResult>();
            int? totalRecord = 0;
            objReturn.Items = DB.AdminInstance.uspLogGetList(keyWord, adminID, functionID, action, servicesID, fromDate, toDate, currentPage, pageSize, ref totalRecord).ToList();
            if (totalRecord != null) objReturn.TotalRecord = totalRecord.Value;
            return objReturn;
        }
    }
}
